﻿using System.Threading.Tasks;
using Magicodes.ExporterAndImporter.Excel.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NP.BPMReportPlatform.PR;
using NP.BPMReportPlatform.PR.Dto;
using NP.BPMReportPlatform.RecurringJobs;
using Volo.Abp.Application.Dtos;

namespace NP.BPMReportPlatform.ZH
{
    /// <summary>
    ///  集团品牌公关中心 接口
    /// </summary>
    //[Authorize]
    [ApiController]
    [Route("api/PR")]
    public class PRController : BPMReportPlatformController
    {
        private readonly IPRService _prService;
        private readonly IAccountOpenChangeRecurringJob _recurringJob;

        public PRController(IPRService prService, IAccountOpenChangeRecurringJob recurringJob)
        {
            _prService = prService;
            _recurringJob = recurringJob;
        }

        /// <summary>
        /// 账号开立申请流程  查询数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("AccountOpenChange/GetAllAsync")]
        public async Task<PagedResultDto<GetAccountOpenChangeOutput>> GetAllAsync([FromBody] GetAccountOpenChangeInput input)
        {
            return await _prService.GetAllAsync(input);
        }

        /// <summary>
        ///  账号开立申请流程   导出数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("AccountOpenChange/ExportAsync")]
        public async Task<XlsxFileResult<GetAccountOpenChangeOutput>> ExportAsync([FromBody] GetAccountOpenChangeInput input)
        {
            var rst = await _prService.ExportAsync(input);
            return new XlsxFileResult<GetAccountOpenChangeOutput>(rst, "导出Excel");
        }

        /// <summary>
        /// 发送提醒邮件
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("AccountOpenChange/SendNoticeEmailForIncompleteAccount")]
        public async Task SendNoticeEmailForIncompleteAccount(string title)
        {
            await _recurringJob.SendNoticeEmailForIncompleteAccount(title);
        }

        /// <summary>
        /// 发送提醒邮件，传入接收邮件
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("AccountOpenChange/SendNoticeEmailToAdminForIncompleteAccount")]
        public async Task SendNoticeEmailToAdminForIncompleteAccount([FromBody] SendNoticeInput input)
        {
            await _recurringJob.SendNoticeEmailToAdminForIncompleteAccount(input.adminEmails, input.title);
        }
    }
}